home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / utils / newalias.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-08  |  3.6 KB  |  135 lines

  1.  
  2. static char rcsid[] = "@(#)$Id: newalias.c,v 5.4 1993/05/08 20:24:55 syd Exp $";
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.4 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1988-1992 USENET Community Trust
  8.  *             Copyright (c) 1986,1987 Dave Taylor
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log: newalias.c,v $
  17.  * Revision 5.4  1993/05/08  20:24:55  syd
  18.  * add sleepmsg for not in elm mode
  19.  *
  20.  * Revision 5.3  1992/10/11  01:10:31  syd
  21.  * Add missing setlocale and catopen (just forgotten)
  22.  * From: Syd
  23.  *
  24.  * Revision 5.2  1992/10/11  00:59:39  syd
  25.  * Fix some compiler warnings that I receive compiling Elm on my SVR4
  26.  * machine.
  27.  * From: Tom Moore <tmoore@fievel.DaytonOH.NCR.COM>
  28.  *
  29.  * Revision 5.1  1992/10/04  00:46:45  syd
  30.  * Initial checkin as of 2.4 Release at PL0
  31.  *
  32.  *
  33.  ******************************************************************************/
  34.  
  35. /** Install a new set of aliases for the 'Elm' mailer. 
  36.  
  37.     If invoked without the -g argument, it assumes that
  38.   it is working with an individual users alias tables, and
  39.   generates the .alias.pag and .alias.dir files in their
  40.   .elm directory.
  41.     If, however, it is invoked with the -g flag,
  42.   it assumes that the user is updating the system alias
  43.   file and uses the defaults for everything.
  44.  
  45.   The format for the input file is;
  46.     alias1, alias2, ... = username = address
  47. or  alias1, alias2, ... = groupname= member, member, member, ...
  48.                                      member, member, member, ...
  49.  
  50. **/
  51.  
  52. #include "elmutil.h"
  53. #include "s_newalias.h"
  54. #include "sysdefs.h"        /* ELM system definitions */
  55.  
  56. void error();
  57.  
  58. #ifdef DEBUG
  59. FILE *debugfile = stderr;
  60. int  debug = 0;
  61. #endif
  62.  
  63. int  is_system=0;        /* system file updating?     */
  64. int  sleepmsg=0;        /* not in elm, dont wait for messages */
  65.  
  66. main(argc, argv)
  67. int argc;
  68. char *argv[];
  69. {
  70.     char inputname[SLEN], dataname[SLEN];
  71.     char home_dir[SLEN];        /* the users home directory  */
  72.     int  a;
  73.  
  74. #ifdef I_LOCALE
  75.     setlocale(LC_ALL, "");
  76. #endif
  77.  
  78.     elm_msg_cat = catopen("elm2.4", 0);
  79.  
  80.     for (a = 1; a < argc; ++a) {
  81.       if (strcmp(argv[a], "-g") == 0)
  82.         is_system = 1;
  83. #ifdef DEBUG
  84.       else if (strcmp(argv[a], "-d") == 0)
  85.         debug = 10;
  86. #endif
  87.       else {
  88.           fprintf(stderr, catgets(elm_msg_cat,
  89.                 NewaliasSet, NewaliasUsage, "Usage: %s [-g]\n"), argv[0]);
  90.           exit(1);
  91.       }
  92.     }
  93.  
  94.     if (is_system) {   /* update system aliases */
  95.         printf(catgets(elm_msg_cat, NewaliasSet, NewaliasUpdateSystem,
  96.                 "Updating the system alias file..."));
  97.  
  98.         strcpy(inputname, system_text_file);
  99.         strcpy(dataname,  system_data_file);
  100.     }
  101.     else {
  102.         printf(catgets(elm_msg_cat, NewaliasSet, NewaliasUpdatePersonal,
  103.         "Updating your personal alias file..."));
  104.     
  105.         if (strcpy(home_dir, getenv("HOME")) == NULL) {
  106.             error(catgets(elm_msg_cat, NewaliasSet, NewaliasNoHOME,
  107.                 "I'm confused - no HOME variable in environment!"));
  108.             exit(1);
  109.         }
  110.  
  111.         MCsprintf(inputname, "%s/%s", home_dir, ALIAS_TEXT);
  112.         MCsprintf(dataname,  "%s/%s", home_dir, ALIAS_DATA); 
  113.     }
  114.  
  115.     if ((a = do_newalias(inputname, dataname, FALSE, TRUE)) < 0) {
  116.         exit(1);
  117.     }
  118.     else {
  119.         printf(catgets(elm_msg_cat, NewaliasSet, NewaliasProcessed,
  120.                 "processed %d aliases.\n"), a);
  121.         exit(0);
  122.     }
  123.  
  124.     /*NOTREACHED*/
  125. }
  126.  
  127. void
  128. error(err_message)
  129. char *err_message;
  130. {
  131.     fflush(stdout);
  132.     fprintf(stderr, "\n%s\n", err_message);
  133.     return;
  134. }
  135.